  /************************/
 /****table 2 model 1 ****/
  /************************/
  
use "C:\Users\RZC0021\Desktop\HACCP results\data of US seafood and non-seafood.dta",clear
global x_list_cool  ln_gdp_o ln_gdp_d ln_distw i.contig i.comlang_off i.col45 i.colony i.curcol ln_area_od i.comcur i.rta 
global lny ln_value 
xtreg $lny i.HACCP##i.Seafood $x_list_cool i.COOL##i.Seafood i.develop_status K* Y* Z*,vce (cluster dist) //table 3 model 1
means $lny if e(sample) & year<1998 & reporter==842 & commoditycode==03
means $lny if e(sample) & year>=1998 & reporter==842 & commoditycode==03
means $lny if e(sample) & year<1998 & reporter==842 & commoditycode!=03
means $lny if e(sample) & year>=1998 & reporter==842 & commoditycode!=03
reg $lny i.HACCP##i.Seafood if e(sample) 

use "C:\Users\RZC0021\Desktop\HACCP results\data of US and EU seafood.dta", clear
global x_list_cool ln_gdp_o ln_gdp_d ln_distw i.contig i.comlang_off i.col45 i.colony i.curcol ln_area_od i.comcur i.rta i.eu i.nafta i.COOL i.cool_US 
global x_list_cool_select ln_gdp_o ln_gdp_d ln_distw i.contig        i.col45 i.colony i.curcol ln_area_od i.comcur i.rta i.eu i.nafta i.COOL i.cool_US  
global lny ln_value 
global y value

xtreg $lny i.HACCP##i.US $x_list_cool i.develop_status K* Y* I*,vce (cluster dist)  //table 3 model 2
means $lny if e(sample) & year<1998 & reporter==842
means $lny if e(sample) & year>=1998 & reporter==842
means $lny if e(sample) & year<1998 & reporter!=842
means $lny if e(sample) & year>=1998 & reporter!=842
reg $lny i.US##i.HACCP if e(sample) 

 /************************/
/****Table A1 and A2 in Appendix****/
 /************************/
 
 gen HACCP=0 if year <1998
replace HACCP=1 if year>=1998

gen COOL=1 if year>=2005
replace COOL=0 if year<2005

xi, prefix(K) I.partner
xi, prefix(Y) I.year

egen pairid=group(reporter partner commoditycode)
drop if commoditycode==.
xtset pairid year
use "C:\Users\RZC0021\Desktop\HACCP results\data of US seafood.dta",clear
global x_list_cool ln_gdp_o ln_gdp_d ln_distw i.contig i.comlang_off i.col45 i.colony i.curcol ln_area_od i.comcur i.rta i.COOL 
global lny ln_value 
global y value

xtreg $lny  HACCP  $x_list_cool  i.develop_status K* Y*,vce (cluster dist)  //Appendix Table A1
outreg2 using US_D.xls, replace ctitle (Model A1-re) keep (HACCP $x_list_cool develop_status)  addtext(Importer fixed effect, No,Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, No, Random effect, No) e(r2_b) dec(3)
xttest0
xi:ppml $y HACCP $x_list_cool i.develop_status, cluster (dist) //Table A2 in appendix 
outreg2 using US_D.xls, append ctitle (Model 2-PPML) keep (HACCP $x_list_cool develop_status)  addtext(Importer fixed effect, No,Exporter fixed effect, Yes,Year fixed effect, No, Commodity fixed effect, No, Random effect, No) e(r2) dec(3)

sum year if e(sample) //1991-2006 model 1
sum value if e(sample) //6.03e+07 
sum HACCP if e(sample) //.5679334 

 /************************/
/****table 3 models 1 ****/
/*******************************/

gen HACCP=0 if year <1998
replace HACCP=1 if year>=1998
gen Seafood=1 if commoditycode==3
replace Seafood=0 if  commoditycode!=3
gen inter=HACCP*Seafood

gen COOL=1 if year>=2005
replace COOL=0 if year<2005
gen cool_seafood=COOL*Seafood
xi, prefix(I) I.reporter
xi, prefix(K) I.partner
xi, prefix(Y) I.year
xi, prefix(Z) I.commoditycode

egen pairid=group(reporter partner commoditycode)
quiet tab pairid,gen(pair_)
drop if commoditycode==.
xtset pairid year
use "C:\Users\RZC0021\Desktop\HACCP results\data of US seafood and non-seafood.dta",clear
global x_list_cool  ln_gdp_o ln_gdp_d ln_distw contig comlang_off col45 colony curcol ln_area_od comcur rta 
global x_list_select  ln_gdp_o ln_gdp_d ln_distw contig           col45 colony curcol ln_area_od comcur rta 
global lny ln_value 
xtreg $lny i.HACCP##i.Seafood $x_list_cool i.COOL##i.Seafood i.develop_status K* Y* Z*,vce (cluster dist) //table 3 model 1
outreg2 using table3.xls, replace ctitle (Model 1 RE with DD) keep (i.HACCP##i.Seafood $x_list_cool i.COOL##i.Seafood i.develop_status##i.Seafood) addtext(Importer fixed effect, No, Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, Yes, Random effect, Yes) e(r2_b) dec(3)
xttest0
 /************************/
/****table 3 models 2 ****/
/*******************************/

gen HACCP=0 if year <1998 
replace HACCP=1 if year>=1998
gen US=1 if reporter==842
replace US=0 if reporter!=842 
gen inter=HACCP*US
gen COOL=1 if year>=2005
replace COOL=0 if year<2005
gen cool_US=COOL*US
xi, prefix(I) I.reporter
xi, prefix(K) I.partner
xi, prefix(Y) I.year

egen pairid=group(reporter partner)
drop if reporter==.|partner==.
xtset pairid year
use "C:\Users\RZC0021\Desktop\HACCP results\data of US and EU seafood.dta", clear
global x_list_cool ln_gdp_o ln_gdp_d ln_distw i.contig i.comlang_off i.col45 i.colony i.curcol ln_area_od i.comcur i.rta i.eu i.nafta i.COOL i.cool_US 
global x_list_cool_select ln_gdp_o ln_gdp_d ln_distw i.contig        i.col45 i.colony i.curcol ln_area_od i.comcur i.rta i.eu i.nafta i.COOL i.cool_US  
global lny ln_value 
global y value

xtreg $lny i.HACCP##i.US $x_list_cool i.develop_status K* Y* I*,vce (cluster dist)  //table 3 model 2
outreg2 using table3.xls, append ctitle (Model 2-RE) keep (i.HACCP##i.US $x_list_cool develop_status)  addtext(Importer fixed effect, Yes, Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, No, Random effect, Yes) e(r2_b) dec(3)
xttest0
sum year if e(sample)  //1988-2006

/************************/
/****table 3 models 3****/
/*******************************/

gen HACCP=0 if year <1998 
replace HACCP=1 if year>=1998
gen US=1 if reporter==842
replace US=0 if reporter!=842
gen Seafood=1 if commoditycode==03
replace Seafood=0 if commoditycode!=03
gen COOL=1 if year>=2005
replace COOL=0 if year<2005
gen cool_us_seafood=COOL*US*Seafood
xi, prefix(I) I.reporter
xi, prefix(K) I.partner
xi, prefix(Y) I.year
xi, prefix(E) I.commoditycode
egen pairid=group(reporter partner commoditycode)
drop if pairid==.
xtset pairid year
use "C:\Users\RZC0021\Desktop\HACCP results\USEU seafood and non seafood.dta",clear
global x_list_cool  ln_gdp_o ln_gdp_d ln_distw i.contig i.comlang_off i.col45 i.colony i.curcol ln_area_od i.comcur i.rta i.eu i.nafta  
global x_list_cool_outcome  ln_gdp_o ln_gdp_d ln_distw i.contig       i.col45 i.colony i.curcol ln_area_od i.comcur i.rta i.eu i.nafta

global lny ln_value 
xtreg $lny i.HACCP##i.Seafood##i.US $x_list_cool i.COOL##i.Seafood##i.US i.develop_statusS K* Y* I* E*, vce (cluster dist)  //table 3 model 3
outreg2 using table3.xls, append ctitle (Model 3-DDD) keep (i.HACCP##i.Seafood##i.US  $x_list_cool i.COOL##i.Seafood##i.US i.develop_status##i.Seafood##i.US)  addtext(Importer fixed effect, Yes, Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, Yes, Random effect, Yes) e(r2_b) dec(3)
xttest0

 /************************/
/****table 4 models 1 ****/
 /************************/
 
gen HACCP=0 if year <1998
replace HACCP=1 if year>=1998
 
gen Seafood=1 if commoditycode==3
replace Seafood=0 if  commoditycode!=3
gen inter=HACCP*Seafood

gen COOL=1 if year>=2005
replace COOL=0 if year<2005
gen cool_seafood=COOL*Seafood


xi, prefix(K) I.partner
xi, prefix(Y) I.year
xi, prefix(Z) I.commoditycode
egen pairid=group(reporter partner commoditycode)
drop if commoditycode==.
xtset pairid year

use "C:\Users\RZC0021\Desktop\HACCP results\data of US seafood and non-seafood.dta",clear
global x_list_cool ln_gdp_o ln_gdp_d ln_distw i.contig i.comlang_off i.col45 i.colony i.curcol ln_area_od i.comcur i.rta  
global x_list_cool_outcome  ln_gdp_o ln_gdp_d ln_distw i.contig    i.col45 i.colony i.curcol ln_area_od i.comcur i.rta 
global lny ln_value 

heckman $lny i.HACCP##i.Seafood  $x_list_cool_outcome i.COOL##i.Seafood i.develop_status K* Y* Z*, select(i.HACCP##i.Seafood  $x_list_cool i.COOL##i.Seafood i.develop_status) rhosigma vce(cluster dist)  //table 4
outreg2 using table4.xls, replace ctitle (Model 4 non-seafood) keep (i.HACCP##i.Seafood $x_list_cool i.COOL##i.Seafood i.develop_status )  addtext(Importer fixed effect, No, Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, Yes, Random effect, No) e(r2) dec(3) //Model 14

 /************************/
/*****table 4 model 2*****/
/*******************************/
xi, prefix(I) I.reporter
xi, prefix(K) I.partner
xi, prefix(Y) I.year

gen HACCP=0 if year <1998 
replace HACCP=1 if year>=1998
 /*creat treatment dummy variable*/
gen US=1 if reporter==842
replace US=0 if reporter!=842 
 //or gen treated=1 if reporter==842 replace treated=0 if reporter!=842
gen inter=HACCP*US
 
gen COOL=1 if year>=2005
replace COOL=0 if year<2005
gen cool_US=COOL*US
egen pairid=group(reporter partner)
drop if reporter==.|partner==.
xtset pairid year
use "C:\Users\RZC0021\Desktop\HACCP results\data of US and EU seafood.dta", clear
global x_list_cool ln_gdp_o ln_gdp_d ln_distw contig comlang_off col45 colony curcol ln_area_od comcur rta eu nafta  
global x_list_cool_outcome ln_gdp_o ln_gdp_d ln_distw contig      col45 colony curcol ln_area_od comcur rta eu nafta 
 
global lny ln_value 
set matsize 1000
heckman $lny i.US##i.HACCP $x_list_cool_outcome i.COOL##i.US i.develop_status K* Y* I*, select(i.US##i.HACCP $x_list_cool i.COOL##i.US i.develop_status K* Y* I*) rhosigma vce(cluster dist) //table 4 model 5
outreg2 using table4.xls, replace ctitle (Model 5-EU seafood) keep (i.US##i.HACCP $x_list_cool i.COOL##i.US i.develop_status)  addtext(Importer fixed effect, Yes, Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, No, Random effect, No) dec(3)

/*******************************/
//*****table 5 Models 1-4*****//
 /************************/
gen HACCP=0 if year <1998
replace HACCP=1 if year>=1998
 
gen Seafood=1 if commoditycode==3
replace Seafood=0 if  commoditycode!=3
gen inter=HACCP*Seafood

gen COOL=1 if year>=2005
replace COOL=0 if year<2005
gen cool_seafood=COOL*Seafood

xi, prefix(K) I.partner
xi, prefix(Y) I.year
xi, prefix(Z) I.commoditycode
egen pairid=group(reporter partner commoditycode)
drop if commoditycode==.
xtset pairid year

use "C:\Users\RZC0021\Desktop\HACCP results\data of US seafood and non-seafood.dta",clear
global x_list_cool ln_gdp_o ln_gdp_d ln_distw i.contig i.comlang_off i.col45 i.colony i.curcol ln_area_od i.comcur i.rta  
global x_list_cool_outcome  ln_gdp_o ln_gdp_d ln_distw i.contig      i.col45 i.colony i.curcol ln_area_od i.comcur i.rta 
global lny ln_value 
xtreg $lny i.HACCP##i.Seafood $x_list_cool i.COOL##i.Seafood  K* Y* Z*,vce(cluster dist), if develop_status==0 
outreg2 using table5.xls, replace ctitle (Model 1) keep (i.HACCP##i.Seafood $x_list_cool i.COOL##i.Seafood)  addtext(Importer fixed effect, No, Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, Yes, Random effect, No) e(r2) dec(3) //table 5 Mdoel 1
xttest0
heckman $lny i.HACCP##i.Seafood  $x_list_cool_outcome i.COOL##i.Seafood K* Y* Z*, select(i.HACCP##i.Seafood  $x_list_cool i.COOL##i.Seafood i.develop_status##i.Seafood ) rhosigma vce(cluster dist)  , if develop_status==1  //table 5 Model 2
outreg2 using table5.xls, replace ctitle (Model ) keep (i.HACCP##i.Seafood $x_list_cool i.COOL##i.Seafood )  addtext(Importer fixed effect, No, Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, Yes, Random effect, No) e(r2) dec(3) 

use "C:\Users\RZC0021\Desktop\HACCP results\data of US and EU seafood.dta", clear
global x_list_cool ln_gdp_o ln_gdp_d ln_distw i.contig i.comlang_off col45 colony curcol ln_area_od comcur rta eu nafta  
global x_list_cool_outcome ln_gdp_o ln_gdp_d ln_distw contig      col45 colony curcol ln_area_od comcur rta eu nafta 
 
global lny ln_value 

xtreg $lny i.US##i.HACCP $x_list_cool  i.COOL##i.US K* Y* I*,vce (cluster dist), if develop_status==0  //table 5 model 3 developed countries H
outreg2 using table5.xls, append ctitle (EU developed) keep (i.US##i.HACCP $x_list_cool i.COOL##i.US)  addtext(Importer fixed effect, Yes, Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, No, Random effect, No) e(r2_b) dec(3)
xttest0
heckman $lny i.US##i.HACCP $x_list_cool_outcome i.COOL##i.US K* Y* I*, select(i.US##i.HACCP  $x_list_cool i.COOL##i.US  K* Y* I*) rhosigma vce(cluster dist), if develop_status==1 //table 5 model 4
outreg2 using table5.xls, append ctitle (EU developed) keep (i.US##i.HACCP $x_list_cool i.COOL##i.US)  addtext(Importer fixed effect, Yes, Exporter fixed effect, Yes,Year fixed effect, Yes, Commodity fixed effect, No, Random effect, No) dec(3)

//Figure 1. U.S. Sseafood imports (03) and U.S. imports of edible, non-seafood imports (6 & 9-18) from overall the world, developed counties and developing countries
use "C:\Users\RZC0021\Desktop\HACCP results\data of US seafood and non-seafood.dta",clear
by year develop_status ,sort: egen import_new=total(value) if commoditycode!=3 
by year develop_status,sort:egen import_new1=total(value) if commoditycode==3
replace import_new1=import_new if import_new1==.
twoway lowess import_new1 year,bwidth(.6), if commoditycode==3 & year>=1991 || lowess import_new1 year,xline(1998) lp(dash), if commoditycode!=3 & year>=1991,saving(us11)
twoway lowess import_new1 year,bwidth(.6), if commoditycode==3 & develop_status==0 & year>=1991 || lowess import_new1 year,xline(1998) lp(dash), if commoditycode!=3 & develop_status==0 & year>=1991,saving(us12,replace)
twoway lowess import_new1 year,bwidth(.6), if commoditycode==3 & develop_status==1 & year>=1991 || lowess import_new1 year,xline(1998) lp(dash), if commoditycode!=3 & develop_status==1 & year>=1991,saving(us13,replace)
gr combine us11.gph us12.gph us13.gph,col(4)

//Figure 2. U.S. Seafood import (03) and EU seafood imports by country
clear all
insheet using "C:\Users\RZC0021\Desktop\HACCP results\euus seafood.csv"
xtset  reportercode year
sum value
gen import=value/1
xtline import,xline(1998)  
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==40,saving(40,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==56,saving(56,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==208,saving(208,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==246,saving(246,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==251,saving(251,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==276,saving(276,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==300,saving(300,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==372,saving(372,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==381,saving(381,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==442,saving(442,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==528,saving(528,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==620,saving(620,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==724,saving(724,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==752,saving(752,replace)
twoway lowess import year,bwidth(.6), if reportercode==842 , lp(dash)|| lowess import year,xline(1998), if reportercode==826,saving(826,replace)
gr combine 40.gph 56.gph 208.gph 246.gph 251.gph 276.gph 300.gph 372.gph 381.gph 442.gph 528.gph 620.gph 724.gph 752.gph 826.gph,col(4)


